package leetcode.p198;

/**
 * @author trtan
 */
public class HouseRobber {
    public static void main(String[] args) {
        int[] nums = {0};
        System.out.println(new HouseRobber().rob(nums));
    }
    public int rob(int[] nums) {
        int len = nums.length;
        if (len == 0) {return 0;}
        int[][] dp = new int[len][2];
        if (len > 0) {
            dp[0][0] = 0;
            dp[0][1] = nums[0];
        }
        if (len > 1) {
            dp[1][0] = dp[0][1];
            dp[1][1] = Math.max(nums[0], nums[1]);
        }
        for (int i = 2; i < len; i++) {
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1]);
            dp[i][1] = dp[i - 1][0] + nums[i];
        }
        return Math.max(dp[len - 1][0], dp[len - 1][1]);
    }
}
